<template>
  <!-- 附表1：2021年度中央企业内部审计工作情况统计表-补充报送项目数 -->
  <j-modal
    :title="'报表上报'"
    :width="800"
    :visible="visible"
    :maskClosable="false"
    :ok-button-props="{ props: { disabled: disableSubmit } }"
    :fullscreen="true"
    @close="close"
    cancelText="关闭"
  >
    <template slot="footer">
      <a-button key="back" style="padding-left: 8px; padding-right: 8px" @click="close(false)"> 关闭 </a-button>
      <a-popconfirm :disabled="disableSubmit" title="确定保存吗?" @confirm="() => saveOrSubmit('save', null)">
        <a-button key="save" style="padding-left: 8px; padding-right: 8px; margin-left: 8px" :disabled="disableSubmit">
          保存
        </a-button>
      </a-popconfirm>
      <a-button
        key="submit"
        type="primary"
        style="padding-left: 8px; padding-right: 8px; margin-left: 8px"
        :disabled="disableSubmit"
        @click="close(true)"
      >
        提交审批
      </a-button>
    </template>
    <a-spin :spinning="Loading">
      <div :class="{ isCheck: isCheck }">
        <!-- <div class="table-header">
          <span class="table-title">填报单位：</span>{{ model.departName }} <span class="table-title">审计负责人：</span
          >{{ model.auditPersonName }} <span class="table-title">填表人：</span>{{ model.createByText }}
          <span class="table-title">填表时间：</span>{{ model.createTime }} <span class="table-title">统计时间：</span
          >{{ model.year }}年（{{ model.quarter }}季度）
        </div> -->
        <a-table
          class="edit-list"
          ref="table"
          size="middle"
          bordered
          width="100vw"
          :pagination="false"
          :columns="columns"
          :dataSource="dataSource"
          :scroll="{ x: 7000 }"
        >
          <div slot="title">
            <div class="title">{{ title }}</div>
            <div class="sub-title">
              <div>填报单位：{{ model.departName }}</div>
              <div>{{ model.year }}年（{{ model.quarter }}季）度</div>
              <div>审计负责人：{{ model.auditPersonName }}</div>
              <div>填表人：{{ model.createByText }}</div>
              <div>填表时间：{{ model.createTime }}</div>
              <div>金额单位（万元）</div>
            </div>
          </div>
          <template slot="customTitle">
            <div class="header-title">企业名称</div>
          </template>
          <template v-slot:a59Title>{{ model.year }}年度内部审计问题已完成整改数（个）</template>
          <template v-slot:a60Title>{{ model.year }}年度内部审计问题整改率（%）</template>
          <template v-slot:a61Title>{{ model.year - 1 }}年度内部审计发现问题整改率（%）</template>
          <template v-for="colrender in customRenderList" v-slot:[colrender]="text, record">
            <span v-if="colrender == 'a1'" :key="colrender">
              <span class="redstar">*</span>
              <j-dict-select-tag
                v-model="record.a1"
                :disabled="disableSubmit"
                class="is-disable-style"
                style="width: calc(100% - 10px)"
                placeholder="请选择集团总部内部审计领导机构类型"
                dict-code="jtzbnbsjldjg_type"
              />
            </span>
            <span v-else-if="colrender == 'a2'" :key="colrender">
              <span class="redstar">*</span>
              <j-dict-select-tag
                v-model="record.a2"
                class="is-disable-style"
                :disabled="disableSubmit"
                style="width: calc(100% - 10px)"
                placeholder="请选择内部审计工作的领导机构"
                dict-code="sys_yes_or_no"
              />
            </span>
            <span v-else-if="colrender == 'a3'" :key="colrender">
              <span class="redstar">*</span>
              <j-dict-select-tag
                v-model="record.a3"
                class="is-disable-style"
                :disabled="disableSubmit"
                style="width: calc(100% - 10px)"
                placeholder="请选择集团总部内部审计部门设置"
                dict-code="jtzbnbsjbmjg_type"
              />
            </span>
            <span v-else-if="colrender == 'a8'" :key="colrender">
              <span class="redstar">*</span>
              <j-dict-select-tag
                v-model="record.a8"
                class="is-disable-style"
                :disabled="disableSubmit"
                style="width: calc(100% - 10px)"
                placeholder="请选择审计信息系统建设应用情况"
                dict-code="sjxxxtjsyyqk_type"
              />
            </span>
            <span v-else-if="!disableSubmit && colrender == 'a0'" :key="colrender">
              <span class="redstar">*</span>
              <a-input
                class="noborderInput"
                style="width: calc(100% - 10px)"
                :disabled="disableSubmit"
                v-model="record[colrender]"
                placeholder="请输入企业名称"
              />
            </span>
            <a-input-number
              v-else-if="!disableSubmit"
              class="inputnumber"
              v-model="record[colrender]"
              :disabled="disableSubmit"
              :key="colrender"
              :min="0"
              :max="10000"
            />
            <div :key="colrender" :class="{ 'title-box-scroll': colrender == 'a0' }" v-else>
              {{ record[colrender] }}
            </div>
          </template>
        </a-table>
      </div>
    </a-spin>
    <SelectApprove ref="approver" @submitData="saveOrSubmit"></SelectApprove>
  </j-modal>
</template>

<script>
import SelectApprove from '../SelectApprover'
import { BbsbModelMixin1 } from './BbsbModelMixin1'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
import columns from './columns10'
export default {
  name: 'ModelView10',
  mixins: [BbsbModelMixin1],
  components: {
    SelectApprove,
  },
  data() {
    return {
      columns: columns(),
      dataSource: [],
      model: {},
      btnStyle: 'save',
      approveId: '',
      type: '1',
      sjType: '8',
      state: '1',
      tableinforIds: [],
      customRenderList: [
        'a0',
        'a1',
        'a2',
        'a3',
        'a4',
        'a5',
        'a6',
        'a7',
        'a8',
        'a9',
        'a10',
        'a12',
        'a15',
        'a17',
        'a19',
        'a20',
        'a11',
        'a13',
        'a14',
        'a16',
        'a18',
        'a21',
        'a22',
        'a23',
        'a24',
        'a25',
        'a26',
        'a27',
        'a28',
        'a29',
        'a30',
        'a31',
        'a32',
        'a33',
        'a34',
        'a35',
        'a36',
        'a37',
        'a38',
        'a39',
        'a40',
        'a41',
        'a42',
        'a43',
        'a44',
        'a45',
        'a46',
        'a47',
        'a48',
        'a49',
        'a50',
        'a51',
        'a52',
        'a53',
        'a54',
        'a55',
        'a56',
        'a57',
        'a58',
        'a59',
        'a60',
        'a61',
      ],
      url: {
        list: '/sjxxzhbb/sjAuditInfo/getGZWOneInfoDetails',
        add: '/sjxxzhbb/sjAuditInfo/addGZWOne',
        edit: '/sjxxzhbb/sjAuditInfo/editGZWOne',
        delete: '/sjxxzhbb/sjAuditInfo/remove',
        submitData: '/common/sjProcCommon/auditGZWOneShen',
        getCreatData: '/sjxxzhbb/sjsbb/queryGZWOneInitData',
      },
    }
  },
  methods: {
    saveOrSubmit(style, approveId) {
      this.btnStyle = style
      this.approveId = approveId
      let flag = true
      let str = ''
      this.dataSource.map((element, index) => {
        if (!(element.a1 && element.a3 && element.a8 && element.a0 && element.a2)) {
          if (flag) flag = false

          this.$message.warning(`第${index + 1}行有必填项${str}未写`)
        }
      })
      if (flag) this.saveData()
    },
    // 数据初始化
    creatReport() {
      getAction(this.url.getCreatData, {
        year: this.model.year,
        quarter: this.model.quarter,
      }).then((res) => {
        if (res.success && res.result[0]) {
          this.dataSource = JSON.parse(res.result[0].info)
          console.log(this.dataSource)
        }
        this.Loading = false
      })
    },
    // 获取报表表格信息
    getTableData() {
      getAction(this.url.list, { id: this.model.id }).then((res) => {
        if (res.success && res.result.length > 0) {
          this.model.departName = res.result[0].departName
          this.model.auditPersonName = res.result[0].headName
          this.model.createByText = res.result[0].createByText
          this.model.year = res.result[0].year
          this.model.quarter = res.result[0].quarter
          let data = []
          res.result[0].info.forEach((element) => {
            // tableinforIds.push(element.id)
            // element.id&&delete element.id
            data = data.concat(JSON.parse(element))
          })
          this.dataSource = data
        }
        this.Loading = false
      })
    },
    saveData() {
      let url, params, method
      // 如果没有auditId字段，表明是新增，如果有表明是修改
      if (this.model.id) {
        url = this.url.edit
        method = 'put'
        params = {
          id: this.model.id,
          info: JSON.stringify(this.dataSource),
          sjType: '8',
        }
      } else {
        method = 'post'
        params = {
          head: this.model.createBy,
          year: this.model.year,
          quarter: this.model.quarter,
          officeId: this.model.officeId,
          info: JSON.stringify(this.dataSource),
          sjType: '8',
        }
        url = this.url.add
      }
      httpAction(url, params, method).then((res) => {
        if (res.success) {
          if (this.btnStyle == 'save') {
            this.$message.success(res.message)
            this.visible = false
            this.$emit('ok')
            return
          } else {
            this.submitData(this.approveId, res.result)
          }
        } else {
          this.$message.error(res.message)
        }
      })
    },
    delete(record, resetTablecall) {
      deleteAction(this.url.delete, { id: record.id }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          // 请求数据
          resetTablecall()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    submitData(userId, proId) {
      getAction(this.url.submitData, {
        // 如果新增就用返回的id否则就用当前数据的id
        proId: this.model.id ? this.model.id : proId,
        userIds: userId,
        type: this.type,
        state: this.state,
        sjType: this.sjType,
        year: this.model.year,
        quarter: this.model.quarter,
        reportInfo: JSON.stringify(this.dataSource),
      }).then((res) => {
        this.Loading = false
        if (res.success) {
          this.$message.success(res.message)
          this.visible = false
          this.$refs.approver.confirmLoading = false
          this.$emit('ok')
        } else {
          console.log(res)
        }
      })
    },
  },
}
</script>

<style lang="less" scoped>
// @import '../../../css/checkAndEdit.less';
@import '../../css/baobiaotable.less';
.input-title {
  height: 30px !important;
}
.table-header {
  margin-bottom: 10px;

  .table-title {
    font-weight: bold;
    margin-left: 15px;
  }
}
.redstar {
  color: red;
  font-size: 24px;
  vertical-align: middle;
}
.edit-list {
  .header-title {
    height: 140px;
    text-align: center;
    line-height: 140px;
  }
  .is-disable-style {
    /deep/ .ant-select-selection {
      border: 0px;
      background: #fff;
      color: rgba(0, 0, 0, 0.65) !important;
    }
  }
  .title-box-scroll {
    width: 100%;
    height: 45px;
    overflow-x: hidden;
    overflow-y: auto;
  }
}
</style>